import org.junit.Test;
import static org.junit.Assert.*;

public class NodeTest {

    @Test
    public void testDefaultConstructor() {
        // check default node creation
        Node node = new Node();
        Term term = node.getTerm();

        assertEquals("", term.getTerm());
        assertEquals(0, term.getWeight());
        assertEquals(0, node.getWords());
        assertEquals(0, node.getPrefixes());

        Node[] refs = node.getReferences();
        assertNotNull(refs);
        assertEquals(26, refs.length);

        for (Node ref : refs) {
            assertNull(ref);
        }
    }

    @Test
    public void testParameterizedConstructorValid() {
        // check node with specific term
        Node node = new Node("apple", 100);
        Term term = node.getTerm();

        assertEquals("apple", term.getTerm());
        assertEquals(100, term.getWeight());
        assertEquals(1, node.getWords());
        assertEquals(0, node.getPrefixes());

        Node[] refs = node.getReferences();
        assertNotNull(refs);
        assertEquals(26, refs.length);

        for (Node ref : refs) {
            assertNull(ref);
        }
    }

    @Test(expected = IllegalArgumentException.class)
    public void testParameterizedConstructorNullQuery() {
        // should throw exception for null term
        new Node(null, 50);
    }

    @Test(expected = IllegalArgumentException.class)
    public void testParameterizedConstructorNegativeWeight() {
        // should throw exception for negative weight
        new Node("apple", -10);
    }

    @Test
    public void testSettersAndGetters() {
        // check all property setters and getters
        Node node = new Node();

        Term newTerm = new Term("banana", 200);
        node.setTerm(newTerm);
        assertEquals("banana", node.getTerm().getTerm());
        assertEquals(200, node.getTerm().getWeight());

        node.setWords(5);
        assertEquals(5, node.getWords());

        node.setPrefixes(10);
        assertEquals(10, node.getPrefixes());

        Node[] newRefs = new Node[26];
        for (int i = 0; i < 26; i++) {
            newRefs[i] = new Node("child" + i, i);
        }
        node.setReferences(newRefs);
        assertArrayEquals(newRefs, node.getReferences());
    }
}
